package com.gmail.shazi199.satoriex.stage.image;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

import com.gmail.shazi199.satoriex.App;
import com.gmail.shazi199.satoriex.entity.Drawable;
import com.gmail.shazi199.satoriex.utils.Drawer;

public class ShowPic implements Drawable {
    
    private static final Log LOGGER = LogFactory.getLog(ShowPic.class);

    private Texture texture;
    private Picture picture;

    @Override
    public void draw() {
        Drawer.draw(texture, picture);
    }

    public ShowPic(String imagePath, int posX, int posY, int width, int height, int picX, int picY) {
        this.picture = new Picture(posX, posY, picX, picY, width, height);
        try {
            init(imagePath);
        } catch (IOException e) {
            LOGGER.error("Load Pic Error", e);
            App.getApp().exit();
        }
    }

    public ShowPic(String imagePath, int posX, int posY, int width, int height) {
        this.picture = new Picture(posX, posY, width, height);
        try {
            init(imagePath);
        } catch (IOException e) {
            LOGGER.error("Load Pic Error", e);
            App.getApp().exit();
        }
    }

    public void init(String imagePath) throws IOException {
        this.texture = TextureLoader.getTexture("PNG", App.class.getResourceAsStream(imagePath));
    }
}
